package com.mes.common.datashard.util;

import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

public class SqlFileReader {
    public static List<String> readSqlFile(String fileName) throws Exception {
        ClassPathResource resource = new ClassPathResource("sql/" + fileName);
        byte[] fileData = FileCopyUtils.copyToByteArray(resource.getInputStream());
        String sqlScript = new String(fileData, StandardCharsets.UTF_8);
        return Arrays.asList(sqlScript.split(";\\s*"));
    }
}
